package io.arukas;

import io.arukas.webservice.HelloService;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by IntelliJ IDEA. <br/>
 *
 * @author 牛玉贤 <br/>
 * @date 08/05/2020 16:10 <br/>
 * @email ncc0706@gmail.com <br/>
 */
@RestController
public class HelloController {

    /**
     * 客户端调用 webservice 服务
     *
     * @param username
     * @param password
     * @param message
     * @return
     */
    @GetMapping("hello")
    public String hello(String username, String password, @RequestParam(defaultValue = "webservice") String message) {
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        jaxWsProxyFactoryBean.setAddress("http://localhost:8000/services/helloworld?wsdl");
        jaxWsProxyFactoryBean.setServiceClass(HelloService.class);
        jaxWsProxyFactoryBean.setUsername(username);
        jaxWsProxyFactoryBean.setPassword(password);
        HelloService helloService = (HelloService) jaxWsProxyFactoryBean.create();
        return helloService.sayHello(message);
    }

}
